/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.test;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import z.h.w.jar.kit.method.Text;

/**
 *
 * @author EnzoZhong
 */
public class NewMain4 {

     static ScheduledExecutorService SERVICE = Executors.newScheduledThreadPool ( Runtime.getRuntime ().availableProcessors () / 2 );

     /**
      * @param args the command line arguments
      * @throws MalformedURLException
      */
     public static void main ( String[] args ) throws MalformedURLException {
          String url = "http://www.my-forum.org/timprimir.php?numero=63597&nforo=319046&pag=";
          Integer[] pages = { 0 , 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 };

          ArrayList<String> urlList = new ArrayList<> ( 500 );
          for ( Integer page : pages ) {
               String newUrl = url + page;
               String context = Text.url2String ( newUrl );
               Pattern pattern = Pattern.compile ( "(http://){1}(.+?)(.jpg){1}" );
               Matcher matcher = pattern.matcher ( context );
               while ( matcher.find () ) {
                    urlList.add ( matcher.group () );
               }
          }

          String filePath = "D:\\Des\\Ariel Rebel\\";
          System.out.println ( "下载列表准备完成" );
          for ( String strUrl : urlList ) {
               Runnable thread = new Download ( strUrl , filePath );
               SERVICE.submit ( thread );
          }
          SERVICE.shutdown ();

     }

}
